/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sekretariat;

import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.stage.Stage;

/**
 *
 * @author onsjo
 */
public class Controller extends Application {
    Stage primaryStage;
    
    private MenuBar bar;
    private Button ninjaMode;
    
    
    @Override
    public void start(Stage stage) throws Exception {
        primaryStage = stage;
        Group root = new Group();
        //set up the scene
        stage.setResizable(false);
        stage.setScene(new Scene(root, 480,480));
        stage.setTitle("DKV-klocka");
        
        //add the menu
        createMenu(root.getChildren());
        //add some buttons
        createButtons(root.getChildren());
        
        //show the created stage
        stage.show();
    }
    
    public static void main(String[] args) throws Exception {
        launch(args);                
    }
    
    //creation of button functions
    private void createButtons(ObservableList<Node> nodes) {
        //create all buttons
        ninjaMode = new Button("Ninja");
        ninjaMode.setLayoutX(50);
        ninjaMode.setLayoutY(50);
        ninjaMode.setOnAction(new EventHandler<ActionEvent>(){
            @Override
            public void handle(ActionEvent t) {
                ninjaMode();
            }
        });
        
        //add all buttons
        nodes.addAll(ninjaMode);
    }
    
    //creation of menu functions
    private void createMenu(ObservableList<Node> nodes) {
        //create the menu bar
        bar = new MenuBar();
        
        //creating the file menu
        Menu menuFile = new Menu("Arkiv");
        MenuItem itemNew = new MenuItem("Nytt häfv");
        itemNew.setOnAction(new EventHandler<ActionEvent>(){
            @Override
            public void handle(ActionEvent t) {
                menuNew();
            }
        });
        MenuItem itemQuit = new MenuItem("Avsluta häfv");
        itemQuit.setOnAction(new EventHandler<ActionEvent>(){
            @Override
            public void handle(ActionEvent t) {
                menuQuit();
            }
        });
        menuFile.getItems().addAll(itemNew,itemQuit);
        
        //attatch all menues(stavning?)
        bar.getMenus().addAll(menuFile);
        nodes.addAll(bar);
    }
    
    //button functions
    //TODO: Build all button functions
    private void ninjaMode(){
        System.out.println("Let's go into ninja mode!!!");
    }
    
    //menu functions
    //TODO: Build all menu functions
    private void menuNew(){
        System.out.println("Create new häfv!");
    }
    private void menuQuit(){
        try {
            primaryStage.close();
        } catch (Exception ex) {
            System.err.println("Unable to stop Controller.");
            System.exit(-1);
        }
    }
}
